﻿/*
.HBDivBox {
position: absolute;
z-index:100;
top: 0px;
left: 0px;
background-color:#000;
filter:alpha(opacity=60);
-moz-opacity: 0.6;
opacity: 0.6;
}
*/
function HBDivBox(name) { //初始化属性
    this.name = name;      //对象名称
    this.time = 2500;
    this.AddStyle();
}
//添加样试
HBDivBox.prototype.AddStyle = function() {
    if (document.all) {
        window.style = ".HBDivBox{position: absolute;z-index:100;top: 0px;left: 0px;background-color:#000;filter:alpha(opacity=60);-moz-opacity: 0.6;opacity: 0.6;}";
        document.createStyleSheet("javascript:style");
    } else { 
        var style = document.createElement('style');
        style.type = 'text/css';
        style.innerHTML = ".HBDivBox{position: absolute;z-index:100;top: 0px;left: 0px;background-color:#000;filter:alpha(opacity=60);-moz-opacity: 0.6;opacity: 0.6;}";
        document.getElementsByTagName('HEAD').item(0).appendChild(style);
    }
}
//显示DIV
HBDivBox.prototype.Show = function(DivID) {
    if (document.getElementById(DivID) == null) { return; }
    this.Layout(DivID);
    var self = this;
    window.onresize = function() { self.Layout(DivID); } //改变窗体重新调整位置
    window.onscroll = function() { self.Layout(DivID); } //滚动窗体重新调整位置

    this.HideSelect();
}
//隐藏DIV
HBDivBox.prototype.Remove = function(DivID) {
    document.getElementById(this.name + '_DivBox_overlay').style.display = "none";
    document.getElementById(DivID).style.display = "none";

    window.onscroll = null;
    window.onresize = null;

    this.ShowSelect();
}
//调整布局
HBDivBox.prototype.Layout = function(DivID) {
    var a = document.getElementById(DivID);

    //判断是否新建遮掩层
    if (document.getElementById(this.name + '_DivBox_overlay') == null) {
        var overlay = document.createElement("div");
        overlay.setAttribute('id', this.name + '_DivBox_overlay');
        overlay.setAttribute('class', 'HBDivBox');
        overlay.className = "HBDivBox";

        a.parentNode.appendChild(overlay);
    }
    //alert(a.style.width + "," + a.style.height);
    //alert("clientWidth:" + window.parent.innerWidth + ",clientHeight:" + window.parent.innerHeight);
    //取客户端左上坐标，宽，高
    var scrollLeft = (document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft);
    var scrollTop = (document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop);
    var clientWidth = document.documentElement.clientWidth;
    var clientHeight = document.documentElement.clientHeight;
    var bo = document.getElementById(this.name + '_DivBox_overlay');
    bo.style.left = scrollLeft + 'px';
    bo.style.top = scrollTop + 'px';
    bo.style.width = clientWidth + 'px';
    bo.style.height = clientHeight + 'px';
    bo.style.display = "";
    //Popup窗口定位
    a.style.position = 'absolute';
    a.style.zIndex = 101;
    a.style.display = "";
    //a.style.left = "40%";
    //a.style.top = "40%";
    //a.style.left = ((document.documentElement.clientWidth - 780) / 2) + "px";
    //a.style.top = "-10px";

    //document.getElementById('setting').style.display = "block";

    a.style.left = ((document.documentElement.clientWidth - a.clientWidth) / 2) + "px";
    var top = (parseInt((document.documentElement.clientHeight - a.clientHeight - 43) / 2));
    top = parseInt((document.documentElement.clientHeight - a.clientHeight - 43) / 2);
    if (top < 0)
        top = 0;
    top += document.documentElement.scrollTop;
    a.style.top = top + "px";
}
//调整布局
HBDivBox.prototype.Show2 = function(DivID) {
    if (document.getElementById(DivID) == null) { return; }
    var a = document.getElementById(DivID);

    //取客户端左上坐标，宽，高
    var scrollLeft = (document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft);
    var scrollTop = (document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop);
    var clientWidth = document.documentElement.clientWidth;
    var clientHeight = document.documentElement.clientHeight;

    //Popup窗口定位
    a.style.display = "";
    a.style.position = 'absolute';
    a.style.zIndex = 101;
    a.style.display = "";

    a.style.left = ((document.documentElement.clientWidth - a.clientWidth) / 2) + "px";
    var top = (parseInt((document.documentElement.clientHeight - a.clientHeight - 43) / 2));
    top = parseInt((document.documentElement.clientHeight - a.clientHeight - 43) / 2);
    if (top < 0)
        top = 0;
    top += document.documentElement.scrollTop;
    a.style.top = top + "px";

    setTimeout(function() { document.getElementById(DivID).style.display = "none"; }, this.time);
}
//隐藏DIV
HBDivBox.prototype.Remove2 = function(DivID) {
    document.getElementById(DivID).style.display = "none";
}


//隐藏select控件
HBDivBox.prototype.HideSelect = function() {
    var selects = document.getElementsByName('select');
    for (i = 0; i < selects.length; i++) {
        selects[i].style.visibility = 'hidden';
    }
}

//显示或隐藏页面上所有的select控件
HBDivBox.prototype.ShowSelect = function() {
    var list_ = document.getElementsByName("select");
    for (var i = 0; i < list_.length; i++) {
        list_[i].style.visibility = 'visible';
    }
}

var HBDivBox = new HBDivBox("HBDivBox");